<template>
  <div > 
    <div>
      <el-form ref="form" size="mini" :model="form" label-width="90px" :rules="rules">
          <el-row>     
            <el-col :span="24">
              <el-form-item label="端口" prop="port"> 
                <el-input  v-model="form.port" ></el-input>
              </el-form-item>
            </el-col> 
          </el-row>
        </el-form>
    </div>

    <div class="center mt">
      <el-button icon="el-icon-circle-close" size="mini" @click="$emit('close')">取 消</el-button>
      <el-button icon="el-icon-circle-plus-outline" :loading="saveLoading" type="primary" v-show="type!='view'" size="mini" @click="saveFn">启 动</el-button>
    </div>
  </div>
</template>

<script>
 
 import * as api from "@/api/upgrade/package";
 import * as nacosApi from "@/api/upgrade/nacos";
 export default {
  props:['type','row'],
  data() {
    return {  
      saveLoading:false,
      goon:false,
      readFlag:false, 
      form:{
        port:''
      },
      rules: {
        port: [
          { required: true, message: '请输入启动端口', trigger: 'change',}
        ]
      },
      props: {
        label: 'dictValue',
        value: 'dictKey'
      }, 
      loadings: false,
      index:0,      
    };
  },
  mounted() {
    this.initDict(); 
    
    if(this.type == 'edit' || this.type == 'view'){
      this.form = {
        ...this.row,
      }
    } 
  },
  methods: {
    initDict(){      
      if(this.type == 'view'){
        this.readFlag = true;
      } else {
        this.readFlag = false;
      }
      var param = {"serviceName":this.row.moduleName};
      nacosApi.getDefaultPort(param).then(
              (res) => {
                console.log(res.data)             
                this.form.port = res.data.data;
              },
            ).catch(()=>{ 
              this.saveLoading = false;
            }
          ); 
    },   
    saveFn() {
      this.$refs.form.validate(valid => {
        if (valid) {
          let row= {
            ...this.form,
          }
          this.saveLoading = true 
          api.backStartModule(row).then(
              (res) => {
                this.$message({
                  type: "success",
                  message: res.data.msg
                });
                this.saveLoading = false;
                this.$emit('reload')
              },
            ).catch(()=>{ 
              this.saveLoading = false;
            });
        }
      }); 
    },
  } 
};
</script>

<style>
.avue-crud__pagination {
  margin-top: 0;
  padding: 0;
}
.option_item {
  flex-shrink: 0;
  height: 28px;
  line-height: 28px;
  padding: 2px 20px;
}
</style>
